package com.daisuxia.web.service;

import org.apache.commons.lang3.StringUtils;
import org.apache.log4j.Logger;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.daisuxia.constant.Constant;
import com.daisuxia.web.dao.IIndexDao;
import com.daisuxia.web.pojo.InfoIndexInfo;
import com.daisuxia.web.pojo.User;

import java.util.HashMap;
/**
 * 用户动态数据设置
 * @author gaoyuhai
 * 2016-12-17 下午05:59:16
 */
@Service
public class InfoIndexService implements IInfoIndexService {
	
	private Logger loger = Logger.getLogger(InfoIndexService.class);
	@Autowired
	private IIndexDao indexDao;

	/**
	 * 更新用户额度
	 * @param map
	 */
	public void changeUserAmount(HashMap<String,Object> map){
		loger.info("提升额度...");
		String userId = null;
		try{
			userId = String.valueOf(map.get("userId"));
		}catch(Exception e){
			loger.info("changeUserAmount map.getkey is error:"+map);
		}
		if(StringUtils.isNotBlank(userId)){
			loger.info("提升额度用户 userId="+userId);
			Integer uId = Integer.parseInt(userId);
			HashMap<String,Object> userMap = new HashMap<String,Object>();
			userMap.put("USER_ID", uId);
			User user = this.indexDao.searchUserByIndex(userMap);
//			loger.info("changeUserAmount user:"+user);
			if(null!=user){
				InfoIndexInfo indexInfo = new InfoIndexInfo();
				indexInfo.setUserId(uId);
				indexInfo.setCardAmount(user.getAmountMax());
				indexInfo.setAmountMin(user.getAmountMin());
				loger.info("额度提升为:"+user.getAmountMax()+" -- "+user.getAmountMin());
				int updateRow = this.indexDao.updateIndexInfoByUserId(indexInfo);
				loger.info("changeUserAmount updateRow:"+updateRow);
			}
		}else{
			loger.info("提升额度用户 userId is null");
		}
	}

	/**
	 * 用户手机认证
	 * @param map
	 */
	public void authMobile(HashMap<String,Object> map){
		loger.info("authMobile start...map:"+map);
		InfoIndexInfo indexInfo = new InfoIndexInfo();
		indexInfo.setUserId(Integer.parseInt(String.valueOf(map.get("userId"))));
		indexInfo.setAuthMobile(Constant.STATUS_INT_VALID);
		this.indexDao.updateIndexInfoByUserId(indexInfo);
	}
}
